package com.feihong.yw189.activity.kaika;

import android.Manifest;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.feihong.yw189.R;
import com.feihong.yw189.activity.base.BaseActivity;
import com.feihong.yw189.adapter.PhoneNumAdapter;
import com.feihong.yw189.app.App;
import com.feihong.yw189.bluetooth.dialog.MyUsualyDialog;
import com.feihong.yw189.global.RequestTools;
import com.feihong.yw189.listener.http.RequestCallBack;
import com.feihong.yw189.message.LoginMessage;
import com.feihong.yw189.model.Kaika.KaiKaNumInfo;
import com.feihong.yw189.model.Kaika.PhoneIsUsedModel;
import com.feihong.yw189.model.Kaika.TelPriceModel;
import com.feihong.yw189.popupwindow.ShowPopupWindow;
import com.feihong.yw189.popupwindow.listener.BackPopMapListener;
import com.google.gson.Gson;
import com.holenzhou.pullrecyclerview.PullRecyclerView;
import com.holenzhou.pullrecyclerview.layoutmanager.XLinearLayoutManager;

import org.xutils.common.Callback;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import permissions.dispatcher.NeedsPermission;
import permissions.dispatcher.OnNeverAskAgain;
import permissions.dispatcher.OnPermissionDenied;
import permissions.dispatcher.OnShowRationale;
import permissions.dispatcher.PermissionRequest;
import permissions.dispatcher.RuntimePermissions;

/**
 * ·
 * 张鹏
 * 选号界面  开卡
 * 2017.2.9
 */
@RuntimePermissions
public class SelectNumActivity extends BaseActivity {

    @BindView(R.id.ed_search)
    EditText edSearch;
    @BindView(R.id.rb_hd)
    RadioButton rbHd;

    @BindView(R.id.rl_hd)
    RelativeLayout rlHd;
    @BindView(R.id.rb_dj)
    RadioButton rbDj;

    @BindView(R.id.rl_dj)
    RelativeLayout rlDj;
    @BindView(R.id.rb_dx)
    RadioButton rbDx;

    @BindView(R.id.rl_dx)
    RelativeLayout rlDx;
    @BindView(R.id.rb_yc)
    RadioButton rbYc;

    @BindView(R.id.rl_yc)
    RelativeLayout rlYc;
    @BindView(R.id.rgp_hd)
    RadioGroup rgpHd;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.txt_pagetitle)
    TextView txtPagetitle;
    @BindView(R.id.iv_lin)
    ImageView ivLin;
    @BindView(R.id.iv_confirm)
    TextView ivConfirm;
    @BindView(R.id.top_back_layout)
    LinearLayout topBackLayout;
    @BindView(R.id.tv_sshm)
    TextView tvSshm;
    @BindView(R.id.ll_line)
    LinearLayout llLine;
    private PopupWindow popupWindow;

    @BindView(R.id.pull_recycler_view)
    PullRecyclerView mPullRecyclerView;

    private int mhmType = 0;
    private ShowPopupWindow showPopupWindow;

    private String search = "";
    /**
     * 页数
     */
    private int page = 1;
    /**
     * 每页条目
     */
    private int pageSize = 10;
    private PhoneNumAdapter mPhoneNumAdapter;

    private String mTcGroupID;
    // 判断选中状态
    private boolean flagHd = false;
    private boolean flagDj = false;
    private boolean flagDx = false;
    private boolean flagYc = false;
    /**
     * 选择的手机号码
     */
    public static final String KAIKA_PHONE_NUM_KEY = "KAIKA_PHONE_NUM_KEY";
    /**
     * 选择的手机号码id
     */
    public static final String KAIKA_PHONE_ID_KEY = "KAIKA_PHONE_ID_KEY";
    public static final String KAIKA_PHONE_TYPE = "KAIKA_PHONE_TYPE";
    public static final String KAIKA_NUM_LEV_MEMO = "Num_LEV_MEMO";
    /**
     * 靓号费
     */
    public static final String KAIKA_NUM_VIRTUAL_PRICE = "KAIKA_NUM_VIRTUAL_PRICE";
    public static final String KAIKA_NUM_PRICE = "KAIKA_NUM_PRICE";
    private String mTelNum;
    private HashMap<String, String> mPhoneMap;

    @BindView(R.id.null_data_layout_txt)
    TextView mNullDataWarningTv;
    @BindView(R.id.null_data_layout)
    RelativeLayout mNullDataLayout;
    @BindView(R.id.select_num_content_layout)
    LinearLayout mContentLayout;
    @BindView(R.id.connect_net_error_layout)
    LinearLayout mConnectNetErrorLayout;
    private MyUsualyDialog progressDialog;
    private Intent mIntent;
    /**
     * 号码类型
     */
    public static final String PHONE_NUM_REQUEST_URL = "PHONE_NUM_REQUEST_URL";
    private String requestUrl;

    /**
     * 已经选择过的号码的集合
     */
    public static final String AL_SELECT_TEL_NUM_KEY = "AL_SELECT_TEL_NUM_KEY";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.select_num);
        ButterKnife.bind(this);

        mPhoneMap = new HashMap<>();
        mIntent = getIntent();
        if (mIntent != null) {
            requestUrl = mIntent.getStringExtra(PHONE_NUM_REQUEST_URL);
            if(TextUtils.isEmpty(requestUrl)){
                showToast("请传入号码类型");
                finish();
            }
            ArrayList<String> arrayList = mIntent.getStringArrayListExtra(AL_SELECT_TEL_NUM_KEY);
            if (arrayList != null) {
                for (String tel : arrayList) {
                    mPhoneMap.put(tel, tel);
                }
            }
        }
        // 获取数据
        mTcGroupID = mIntent.getStringExtra(ChooseTaoCanActivity.KAIKA_SELECT_PACAKGE_GROUPID_KEY);

        initView();
        initData();
    }

    @Override
    public void setTheme() {

    }

    @Override
    public void onUserLogin(LoginMessage loginMessage) {

    }

    /**
     * 初始化数据
     */
    private void initData() {

        mPhoneNumTypeMap = new HashMap<>();
        setPageTitle("手机号码");
        ivLin.setVisibility(View.GONE);
        ivBack.setOnClickListener(v -> finish());
        // 默认加载数据
        mPullRecyclerView.autoRefresh();
    }

    private void noDataLayout() {
        if (mNullDataLayout.getVisibility() == View.GONE) {
            mConnectNetErrorLayout.setVisibility(View.GONE);
            mNullDataLayout.setVisibility(View.VISIBLE);
        }
    }

    private void connectNetErrorLayout() {
        if (mConnectNetErrorLayout.getVisibility() == View.GONE) {
            mNullDataLayout.setVisibility(View.GONE);
            mConnectNetErrorLayout.setVisibility(View.VISIBLE);
        }
    }

    private void normalLayout() {
        if (mConnectNetErrorLayout.getVisibility() == View.VISIBLE || mNullDataLayout.getVisibility() == View.VISIBLE) {
            mConnectNetErrorLayout.setVisibility(View.GONE);
            mNullDataLayout.setVisibility(View.GONE);
            mPullRecyclerView.setVisibility(View.VISIBLE);
        }
    }

    private int dataSize = 0;

    private Callback.Cancelable mCancelable;
    /**
     * 请求数据
     */
    private void getNet() {
        if(mCancelable != null && !mCancelable.isCancelled()){
            mCancelable.cancel();
        }
        search = edSearch.getText().toString().trim();
        mCancelable = App.getApp().getHttpTools().getPhoneNum(mTcGroupID, mPhoneNumTypeMap, search, page, pageSize, mRequestCallBack, requestUrl);
    }

    private RequestCallBack mRequestCallBack = new RequestCallBack<String>() {

        @Override
        public void onSuccess(String result) {
            if (activityIsDestory()) {
                return;
            }
            Gson gson = new Gson();
            // 记得用try catch包裹,提示服务器返回数据异常
            try {
                KaiKaNumInfo kaiKaNumInfo = gson.fromJson(result, KaiKaNumInfo.class);
                if (kaiKaNumInfo != null) {
                    if (kaiKaNumInfo.getStatus() == 1) {

                        KaiKaNumInfo.DataBean data = kaiKaNumInfo.getData();

                        if (data.getList() == null || data.getList().size() == 0) {
                            mPullRecyclerView.enableLoadMore(false);
                            if (dataSize == 0) {
                                noDataLayout();
                            }
                        } else {
                            if (data.getList().size() < pageSize) {
                                mPullRecyclerView.enableLoadMore(false);
                            } else {
                                page++;
                            }
                            normalLayout();
                            dataSize += data.getList().size();
                            mPullRecyclerView.setVisibility(View.VISIBLE);
                            mPhoneNumAdapter.addAll(data.getList());
                        }
                    } else {
                        if (dataSize <= 0) {
                            noDataLayout();
                        }
                        showToast(kaiKaNumInfo.getInfo());
                    }
                } else {
                    if (dataSize <= 0) {
                        noDataLayout();
                    }
                }
            } catch (Exception e) {
                if (dataSize <= 0) {
                    noDataLayout();
                }
            }
        }

        @Override
        public void onError(Throwable ex, boolean isOnCallback) {
            if (activityIsDestory()) {
                return;
            }
            ex.printStackTrace();
            if (dataSize <= 0) {
                connectNetErrorLayout();
            } else {
                showToast(getResources().getString(R.string.connect_sever_error_toast));
            }
        }

        @Override
        public void onCancelled(Callback.CancelledException cex) {
        }

        @Override
        public void onFinished() {
            if (activityIsDestory()) {
                return;
            }
            if (mPullRecyclerView != null) {
                mPullRecyclerView.postDelayed(() -> {
                    mPullRecyclerView.stopLoadMore();
                    mPullRecyclerView.stopRefresh();
                }, 300);
            }
        }
    };

    // 查询刷新
    private void searchRef() {
        page = 1;
        // 重新获取搜索值
        dataSize = 0;
        mPullRecyclerView.autoRefresh();
    }

    private Map<String, String> mPhoneNumTypeMap;

    @Override
    protected void onResume() {
        super.onResume();
    }

    private void initView() {
        progressDialog = new MyUsualyDialog(this, R.layout.wait_item);
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.setCancelable(false);
        mNullDataLayout.setVisibility(View.GONE);
        mNullDataWarningTv.setText("无对应条件的号码信息");

        mPhoneNumAdapter = new PhoneNumAdapter(this);
        mPhoneNumAdapter.setItemSelectListener(new KaikaPhoneNumItemSelectListener());
        // 设置数据适配器
        mPullRecyclerView.setAdapter(mPhoneNumAdapter);
        mPullRecyclerView.setLayoutManager(new XLinearLayoutManager(this));
        // 设置下拉刷新的旋转圆圈的颜色
        mPullRecyclerView.setColorSchemeResources(R.color.appBlue);
        // 开启下拉刷新，默认即为true，可不用设置
        mPullRecyclerView.enablePullRefresh(true);

        mPullRecyclerView.enableLoadMore(false);

        mPullRecyclerView.setOnRecyclerRefreshListener(new PullRecyclerView.OnRecyclerRefreshListener() {
            @Override
            public void onPullRefresh() {
                // 刷新
                mPullRecyclerView.enableLoadDoneTip(false, R.string.load_done_tip);
                page = 1;
                dataSize = 0;
                mPullRecyclerView.enableLoadMore(true);
                mPhoneNumAdapter.clear();
                getNet();
            }

            @Override
            public void onLoadMore() {
                // 加载
                mPullRecyclerView.enableLoadDoneTip(true, R.string.load_done_tip);
                getNet();
            }
        });
        // 做出搜索
        showPopupWindow = new ShowPopupWindow(SelectNumActivity.this, new BackPopMapListener() {
            @Override
            public void backPopMap() {
                if (popupWindow != null && popupWindow.isShowing()) {
                    clearAllTypeStatus();
                    popupWindow.dismiss();
                }
                // 做出搜索
                mPhoneNumAdapter.clear();
                dataSize = 0;
                Log.i(TAG, "backPopMap:  " + mPhoneNumTypeMap.toString());
                String mHDStr = mPhoneNumTypeMap.get(ShowPopupWindow.SELECT_PHONENUM_HAODUAN);
                String mDJStr = mPhoneNumTypeMap.get(ShowPopupWindow.SELECT_PHONENUM_DENGJI);
                String mDXStr = mPhoneNumTypeMap.get(ShowPopupWindow.SELECT_PHONENUM_DIXIAO);
                String mYCStr = mPhoneNumTypeMap.get(ShowPopupWindow.SELECT_PHONENUM_YUCUN);

                if (!TextUtils.isEmpty(mHDStr)) {
                    if (mHDStr.equals("全部")) {
                        mPhoneNumTypeMap.remove(ShowPopupWindow.SELECT_PHONENUM_HAODUAN);
                        rbHd.setText("号段");
                    } else {
                        rbHd.setText(mHDStr);
                    }
                }
                if (!TextUtils.isEmpty(mDJStr)) {
                    if (mDJStr.equals("全部")) {
                        mPhoneNumTypeMap.remove(ShowPopupWindow.SELECT_PHONENUM_DENGJI);
                        rbDj.setText("等级");
                    } else {
                        rbDj.setText(mDJStr + "级");
                    }
                }
                if (!TextUtils.isEmpty(mDXStr)) {
                    if (mDXStr.equals("全部")) {
                        mPhoneNumTypeMap.remove(ShowPopupWindow.SELECT_PHONENUM_DIXIAO);
                        rbDx.setText("低销");
                    } else {
                        rbDx.setText(mDXStr + "元");
                    }
                }
                if (!TextUtils.isEmpty(mYCStr)) {
                    if (mYCStr.equals("全部")) {
                        mPhoneNumTypeMap.remove(ShowPopupWindow.SELECT_PHONENUM_YUCUN);
                        rbYc.setText("预存");
                    } else {
                        rbYc.setText(mYCStr + "元");
                    }
                }
                searchRef();
            }
        });
        showPopupWindow.addPhoneNumTypeListener(new ShowPopupWindow.AddPhoneNumTypeListener() {
            @Override
            public void addPhoneNumTypeListener(Map<String, String> phoneNumType) {
                mPhoneNumTypeMap.putAll(phoneNumType);
            }
        });
        popupWindow = showPopupWindow.showPopupWindow(new ShowPopupWindow.ChangeArrowListener() {
            @Override
            public void changeArrowListener() {
                clearAllTypeStatus();
            }
        });
        showPopupWindow.setData(mhmType);
    }

    @OnClick({R.id.rb_hd, R.id.rb_dj, R.id.rb_dx, R.id.rb_yc, R.id.tv_sshm, R.id.requery_data_tv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_sshm:
                mPullRecyclerView.autoRefresh();
                break;
            case R.id.rb_hd:
                // 号段
                if (flagHd) {
                    flagHd = false;
                    phoneNumTypeNormalStatus(rlHd, PHONENUM_TYPE_HAODUAN);
                } else {
                    flagHd = true;
                    phoneNumTypeCheckStatus(PHONENUM_TYPE_HAODUAN, R.id.rb_hd, rlHd);
                }
                break;
            case R.id.rb_dj:
                // 等级
                if (flagDj) {
                    flagDj = false;
                    phoneNumTypeNormalStatus(rlDj, PHONENUM_TYPE_DENGJI);
                } else {
                    flagDj = true;
                    phoneNumTypeCheckStatus(PHONENUM_TYPE_DENGJI, R.id.rb_dj, rlDj);
                }

                break;
            case R.id.rb_dx:
                // 低消
                if (flagDx) {
                    phoneNumTypeNormalStatus(rlDx, PHONENUM_TYPE_DIXIAO);
                } else {
                    flagDx = true;
                    phoneNumTypeCheckStatus(PHONENUM_TYPE_DIXIAO, R.id.rb_dx, rlDx);
                }
                break;
            case R.id.rb_yc:
                // 预存
                if (flagYc) {
                    flagYc = false;
                    phoneNumTypeNormalStatus(rlYc, PHONENUM_TYPE_YUCUN);
                } else {
                    flagYc = true;
                    phoneNumTypeCheckStatus(PHONENUM_TYPE_YUCUN, R.id.rb_yc, rlYc);
                }
                break;
            case R.id.requery_data_tv:
                normalLayout();
                mPullRecyclerView.autoRefresh();
                break;
            default:
                break;
        }
    }

    /**
     * 设置返回键不关闭应用,回到上一页
     *
     * @param keyCode
     * @param event
     * @return
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @NeedsPermission(Manifest.permission.CALL_PHONE)
    void needpermission() {
        if (!TextUtils.isEmpty(mTelNum)) {
            Intent inte1 = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + mTelNum));
            startActivity(inte1);
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        SelectNumActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);
    }

    @OnShowRationale(Manifest.permission.CALL_PHONE)
    void showRational(final PermissionRequest request) {
        new AlertDialog.Builder(this)
                .setPositiveButton("允许", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(@NonNull DialogInterface dialog, int which) {
                        request.proceed();
                    }
                })
                .setNegativeButton("拒绝", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(@NonNull DialogInterface dialog, int which) {
                        request.cancel();
                    }
                })
                .setCancelable(false)
                .setMessage("请允许获取打电话权限")
                .show();
    }

    @OnPermissionDenied(Manifest.permission.CALL_PHONE)
    void Denied() {
        showErrorDialog("权限不足", "您没有开启此应用的使用打电话权限。请到系统设置-->权限管理 开启打电话使用权限。如果您的手机上安装了第三方应用管家（360管家，腾讯管家等），请开启一下打电话权限！", new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                finish();
            }
        });
    }

    @OnNeverAskAgain(Manifest.permission.CALL_PHONE)
    void AskAgin() {
        showErrorDialog("权限不足", "您没有开启此应用的使用打电话权限。请到系统设置-->权限管理 开启打电话使用权限。如果您的手机上安装了第三方应用管家（360管家，腾讯管家等），请开启一下打电话权限！", new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                finish();
            }
        });
    }

    public final static int PHONENUM_TYPE_HAODUAN = 1;
    public final static int PHONENUM_TYPE_DENGJI = 2;
    public final static int PHONENUM_TYPE_DIXIAO = 3;
    public final static int PHONENUM_TYPE_YUCUN = 4;

    class KaikaPhoneNumItemSelectListener implements PhoneNumAdapter.AddPhoneNumItemListener {

        @Override
        public void setPhoneNumItemListener(final KaiKaNumInfo.DataBean.ListBean phoneData) {
            if (mPhoneMap.containsKey(phoneData.getPhonenum())) {
                showToast("此号码已选择，请选择其他号码");
            } else {
                progressDialog.show();
                progressDialog.setWarningTxt(R.id.progress_layout_warning_tv,"正在验证");
                Callback.Cancelable Cancelable = App.getApp().getHttpTools().phoneIsUsed(phoneData.getPhonenum(), phoneData.getType(), new RequestCallBack<String>() {
                    @Override
                    public void onSuccess(String result) {
                        if (activityIsDestory()) {
                            return;
                        }
                        progressDialog.dismiss();
                        PhoneIsUsedModel isUsedModel = JSON.parseObject(result, PhoneIsUsedModel.class);
                        if (isUsedModel.getStatus() == 0) {
                            //号码不可用
                            showErrorToast(isUsedModel.getInfo());
                            return;
                        } else {
                            mIntent.putExtra(KAIKA_PHONE_NUM_KEY, phoneData.getPhonenum());
                            mIntent.putExtra(KAIKA_PHONE_ID_KEY, phoneData.getRegion_id());
                            mIntent.putExtra(KAIKA_PHONE_TYPE, phoneData.getType_phone());
                            mIntent.putExtra(KAIKA_NUM_LEV_MEMO, phoneData.getNum_lev_memo());
                            mIntent.putExtra(KAIKA_NUM_PRICE, phoneData.getReal_price());
                            mIntent.putExtra(KAIKA_NUM_VIRTUAL_PRICE, phoneData.getVirtual_price());
                            setResult(RESULT_OK, mIntent);
                            finish();
                        }
                    }

                    @Override
                    public void onError(Throwable ex, boolean isOnCallback) {
                        if(activityIsDestory()){return;}
                        progressDialog.dismiss();
                        showToast(getResources().getString(R.string.connect_sever_error_toast));
                    }

                    @Override
                    public void onCancelled(Callback.CancelledException cex) {
                    }

                    @Override
                    public void onFinished() {
                    }
                });
                RequestTools.addNewRequest(SelectNumActivity.class.getName(), Cancelable);
            }
        }

        @Override
        public void setCallPhoneNumListener(String callPhone) {
            mTelNum = callPhone;
            SelectNumActivityPermissionsDispatcher.needpermissionWithCheck(SelectNumActivity.this);
        }
    }

    /**
     * 选中状态
     *
     * @param index
     * @param resID
     * @param typeView
     */
    private void phoneNumTypeCheckStatus(int index, int resID, View typeView) {

        if (!popupWindow.isShowing()) {
            showPopupWindow.setData(index);
            rgpHd.check(resID);
            typeView.setVisibility(View.VISIBLE);
            popupWindow.showAsDropDown(llLine);
        } else {
            showPopupWindow.setData(index);
        }
        otherTypeStatus(index);
    }

    /**
     * 未选中状态
     *
     * @param typeView
     * @param index
     */
    private void phoneNumTypeNormalStatus(View typeView, int index) {

        rgpHd.clearCheck();
        typeView.setVisibility(View.INVISIBLE);
        if (popupWindow.isShowing()) {
            popupWindow.dismiss();
        }
        otherTypeStatus(index);
    }

    private void otherTypeStatus(int index) {
        switch (index) {
            case PHONENUM_TYPE_HAODUAN:
                rlDj.setVisibility(View.INVISIBLE);
                rlDx.setVisibility(View.INVISIBLE);
                rlYc.setVisibility(View.INVISIBLE);
                flagDj = false;
                flagDx = false;
                flagYc = false;
                break;
            case PHONENUM_TYPE_DENGJI:
                rlHd.setVisibility(View.INVISIBLE);
                rlDx.setVisibility(View.INVISIBLE);
                rlYc.setVisibility(View.INVISIBLE);
                flagHd = false;
                flagDx = false;
                flagYc = false;
                break;
            case PHONENUM_TYPE_DIXIAO:
                rlHd.setVisibility(View.INVISIBLE);
                rlDj.setVisibility(View.INVISIBLE);
                rlYc.setVisibility(View.INVISIBLE);
                flagHd = false;
                flagDj = false;
                flagYc = false;
                break;
            case PHONENUM_TYPE_YUCUN:
                rlHd.setVisibility(View.INVISIBLE);
                rlDj.setVisibility(View.INVISIBLE);
                rlDx.setVisibility(View.INVISIBLE);
                flagHd = false;
                flagDj = false;
                flagDx = false;
                break;
            default:
                break;
        }
    }

    /**
     * 清空所有状态
     */
    private void clearAllTypeStatus() {
        rgpHd.clearCheck();
        rlHd.setVisibility(View.INVISIBLE);
        rlDj.setVisibility(View.INVISIBLE);
        rlDx.setVisibility(View.INVISIBLE);
        rlYc.setVisibility(View.INVISIBLE);
        flagHd = false;
        flagDj = false;
        flagDx = false;
        flagYc = false;
    }
}